package com.wnxy.sddfp.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class TokenUtils {
    public static String getUserIdByToken(String key) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("token");
        JwtTemplate jwtTemplate = new JwtTemplate();
        Object userId = jwtTemplate.parseToken(token, key);
        return userId.toString();
    }
}